package com.brainhealth.web.controller.customer;


import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.convert.Convert;
import com.brainhealth.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.brainhealth.common.annotation.Log;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.common.enums.BusinessType;
import com.brainhealth.customer.domain.ScoreMallGoods;
import com.brainhealth.customer.service.IScoreMallGoodsService;
import com.brainhealth.common.utils.poi.ExcelUtil;
import com.brainhealth.common.core.page.TableDataInfo;

/**
 * 商城商品信息Controller
 * 
 * @author wolong
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/customer/mallGoods")
public class ScoreMallGoodsController extends BaseController
{
    @Autowired
    private IScoreMallGoodsService scoreMallGoodsService;

    /**
     * 查询商城商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScoreMallGoods scoreMallGoods)
    {
        startPage();
        List<ScoreMallGoods> list = scoreMallGoodsService.selectScoreMallGoodsList(scoreMallGoods);
        return getDataTable(list);
    }

    /**
     * 导出商城商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoods:export')")
    @Log(title = "商城商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoreMallGoods scoreMallGoods)
    {
        List<ScoreMallGoods> list = scoreMallGoodsService.selectScoreMallGoodsList(scoreMallGoods);
        ExcelUtil<ScoreMallGoods> util = new ExcelUtil<ScoreMallGoods>(ScoreMallGoods.class);
        util.exportExcel(response, list, "商城商品信息数据");
    }

    /**
     * 获取商城商品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scoreMallGoodsService.selectScoreMallGoodsById(id));
    }

    /**
     * 新增商城商品信息
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoods:add')")
    @Log(title = "商城商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoreMallGoods scoreMallGoods)
    {
        return toAjax(scoreMallGoodsService.insertScoreMallGoods(scoreMallGoods));
    }

    /**
     * 修改商城商品信息
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoods:edit')")
    @Log(title = "商城商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoreMallGoods scoreMallGoods)
    {
        return toAjax(scoreMallGoodsService.updateScoreMallGoods(scoreMallGoods));
    }

    /**
     * 删除商城商品信息
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoods:remove')")
    @Log(title = "商城商品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scoreMallGoodsService.deleteScoreMallGoodsByIds(ids));
    }

    /**
     * 用商品分类ID获取商品信息
     */
    @Anonymous
    @RequestMapping("/getMallGoodsByCategoryId")
    public AjaxResult getMallGoodsByCategoryId(@RequestBody Map<String, Object> map)
    {
        Long categoryId = Convert.toLong(map.get("categoryId"));
        return success(scoreMallGoodsService.getMallGoodsByCategoryId(categoryId));
    }

    /**
     * 根据商品ID获取商品信息
     * @param map
     * @return
     */
    @Anonymous
    @PostMapping("/getMallGoodsById")
    public AjaxResult getMallGoodsById(HttpServletRequest request,  @RequestBody Map<String, Object> map)
    {
        Long goodsId = Convert.toLong(map.get("goodsId"));
        ScoreMallGoods scoreMallGoods = scoreMallGoodsService.selectScoreMallGoodsByCustomerId(request, goodsId);
        return success(scoreMallGoods);
    }

    /**
     * 根据商品类型查询出商品信息
     * @param map
     * @return
     */
    @Anonymous
    @PostMapping("/getAIPackageGoods")
    public AjaxResult getAIPackageGoods()
    {
        ScoreMallGoods result = scoreMallGoodsService.getAIPackageGoods();
        if (result != null)
        {
            return AjaxResult.success("查询语音包信息成功！", result);
        }
        return AjaxResult.error("查询语音包信息失败！");
    }

}
